Skip to content

fix,ci: P0 runtime safety fixes and CI/CD hardening - #73

Merged
TrezorHannes merged 3 commits into
mainfrom
fix/p0-runtime-safety-and-ci
Nov 26, 2026
Merged

TrezorHannes merged 3 commits into
mainfrom
fix/p0-runtime-safety-and-ci

Conversation

@TrezorHannes

Copy link
Copy Markdown
Owner

Summary of Changes

PR 1 of the phased Lightning-Python-Tools optimization plan (P0 runtime safety fixes & CI/CD foundation ahead of the unified installer PR):

  • P0 Runtime Safety Fixes
    • Other/fee_adjuster.py: atomically replace fee_adjuster.txt (0o644) instead of appending duplicate stanzas on every run; fail non-zero (SystemExit(1)) on fatal top-level errors instead of sleeping 60s and exiting 0; add DEFAULT_HTTP_TIMEOUT = 30.
    • LNBits/pocketmoney.py: gate "Transferred..." logs/Telegram alerts and check_balance() on pay_invoice() succeeding; exit 1 in --run-once mode on failures; add DEFAULT_HTTP_TIMEOUT = 30.
    • Magma/magma_sale_process.py: read [loop] rpcserver/tlscertpath and expand ~ via os.path.expanduser before subprocess.Popen.
    • Peerswap/peerswap-lndg_push.py: guard locale.setlocale against locale.Error, use safe config.get(..., fallback=...) at import time, add DEFAULT_HTTP_TIMEOUT = 30, and run argparse.parse_args() before invoking lncli/pscli.
    • LNDg/channel_fee-pull.py: make import side-effect-safe (main() + __main__), strip base_fee_ignore pubkeys, atomically write 0_fee.txt (0o644), and add DEFAULT_HTTP_TIMEOUT = 30.
    • Peerswap/peerswap-bot.py: make import side-effect-safe (run_bot() + __main__), fix PATH_COMMAND double-slash (os.path.join / [paths] pscli_path), require non-empty TELEGRAM_USER_ID, and add timeout=15 to get_node_alias.
    • LNDg/{channel_base-fee,disabled_fee-accelerator,mempool_rebalancer_trigger,swap_out-candidates}.py: add DEFAULT_HTTP_TIMEOUT = 30 to requests calls.
  • CI/CD & Packaging Foundation
    • Add [project] metadata (requires-python = ">=3.11,<3.14"), [project.optional-dependencies] (db, dev), [tool.ruff], and [tool.coverage.*] to pyproject.toml.
    • Add minimum version bounds + ruff/pip-audit to requirements-dev.txt and expand .gitignore for .ruff_cache/, *.flag, *.pid, .lpt-state.json, .lpt-backups/.
    • Update .github/dependabot.yml with github-actions weekly updates.
    • Expand .github/workflows/tests.yml with parallel lint (ruff + bash -n + shellcheck), security (pip-audit), weekly schedule, timeout-minutes: 10, and --cov-fail-under=35.

Verification

  • .venv/bin/pytest tests/ -v --cov=LNDg --cov=Magma --cov=Other --cov=Peerswap --cov=LNBits --cov-report=term --cov-fail-under=35: 209 passed (40.81% total coverage).
  • .venv/bin/python -m py_compile on all modified scripts and tests/test_p0_runtime_safety.py: passed.
  • bash -n LNBits/install_pocketmoney_service.sh Other/install_fee_adjuster_service.sh: passed.
  • .venv/bin/python -m pip_audit: No known vulnerabilities found.
  • Note: Greptile is not enabled / unavailable locally (greptile-guard), so this PR is verified via GitHub Actions CI + TunnelSentinel.

- Other/fee_adjuster.py: replace append-mode fee_adjuster.txt writes with atomic 0o644 replacement, exit non-zero on fatal errors instead of sleeping 60s, and add DEFAULT_HTTP_TIMEOUT=30.
- LNBits/pocketmoney.py: add DEFAULT_HTTP_TIMEOUT=30, gate success alerts/balance checks on successful pay_invoice() result, and exit 1 in --run-once mode on payment failures.
- Magma/magma_sale_process.py: read [loop] rpcserver/tlscertpath and expand ~ in tlscertpath before Popen.
- Peerswap/peerswap-lndg_push.py: guard locale.setlocale errors, use safe config.get fallbacks, add timeouts, and parse CLI args before invoking lncli/pscli.
- LNDg/channel_fee-pull.py & Peerswap/peerswap-bot.py: make imports side-effect-safe with __main__ guards, safe config fallbacks, atomic 0_fee.txt write, normalized pscli path, and HTTP timeouts.
- LNDg/{channel_base-fee,disabled_fee-accelerator,mempool_rebalancer_trigger,swap_out-candidates}.py: add explicit HTTP timeouts.
- tests/test_p0_runtime_safety.py: add regression tests covering all P0 fixes (209/209 passing, 40.81% total coverage).
…ecurity CI

- Add [project] metadata (requires-python >=3.11,<3.14), optional db/dev extras, ruff config, and coverage settings in pyproject.toml.
- Pin minimum bounds in requirements-dev.txt and expand .gitignore for runtime flags/state/caches.
- Add github-actions weekly updates to .github/dependabot.yml.
- Add parallel lint (ruff + bash -n + shellcheck), pip-audit security job, weekly schedule, job timeouts, and 35% coverage gate in .github/workflows/tests.yml.
@TrezorHannes TrezorHannes added bug Something isn't working enhancement New feature or request python Pull requests that update python code labels Nov 26, 2026
@TrezorHannes TrezorHannes self-assigned this Nov 26, 2026

@tunnelsentinel tunnelsentinel Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TunnelSentinel: 2 new findings on commit `ea4bb1d`, inline below. The TunnelSentinel summary comment on this pull request has the full review.

Comment thread .github/workflows/tests.yml Resolved
Comment thread Other/fee_adjuster.py Resolved
@tunnelsentinel

tunnelsentinel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🛡️⚡ TunnelSentinel Code Review

Verdict: COMMENT (LGTM. High-Risk Tier: a maintainer merges) | Confidence: 5/5 | Risk Tier: HIGH
"Zero leaks. Fail-closed verification."


Latest commit: 8827d49 | Status: success | Reviewed: 2026-11-26 21:27 UTC

Executive Summary

Targeted re-review of commit 8827d49aa2cf5137f697fbe01277f7bab5b67e15 on TrezorHannes/Lightning-Python-Tools#73 (fix/p0-runtime-safety-and-ci). Both previously raised findings (P1 CI pipefail masking and P2 dropping unchanged peers from fee_adjuster.txt) have been verified fixed with zero regressions.

Verified Fixes & Edge-Case Checks

  • [P1 Fixed] CI Coverage Pipe Failure Propagation (.github/workflows/tests.yml:43-54): Added shell: bash and set -o pipefail ahead of pytest ... --cov-fail-under=35 | tee pytest_cov.txt, ensuring test failures and coverage threshold violations fail the Python 3.12 CI job rather than being masked by tee.
  • [P2 Fixed] Complete fee_adjuster.txt Snapshot Across Runs (Other/fee_adjuster.py:1884-1898, tests/test_p0_runtime_safety.py:52-149): Removed the updated_any_channel gate from charge_lnd_entries.append(...) so every processed peer is included in the atomic write_charge_lnd_entries_atomic snapshot even when delta <= fee_delta_threshold or LNDg_fee_update is disabled, while still guarding against empty writes on total API failure (and charge_lnd_entries at line 1906).

Empirical Test Results

  • .venv/bin/pytest tests/ -v --cov=LNDg --cov=Magma --cov=Other --cov=Peerswap --cov=LNBits --cov-report=term --cov-fail-under=35: 210 passed in 1.98s, 42.51% total coverage (meets --cov-fail-under=35).
  • bash -n LNBits/install_pocketmoney_service.sh Other/install_fee_adjuster_service.sh: exited 0.

Recommendation

Clean pass (5/5, HIGH Risk Tier — LGTM. High-Risk Tier: a maintainer merges).

Review history

  • 8827d49: COMMENT (LGTM. High-Risk Tier: a maintainer merges), 5/5, HIGH risk, status success, 2026-11-26 21:27 UTC
  • ea4bb1d: REQUEST_CHANGES, 3/5, HIGH risk, status failure, 2 inline findings, 2026-11-26 21:24 UTC

… peer snapshot

- .github/workflows/tests.yml: set shell: bash and set -o pipefail on the Python 3.12 pytest | tee step so test or coverage failures cannot be masked by tee.
- Other/fee_adjuster.py: collect charge-lnd stanzas for all processed peers regardless of whether an individual peer crossed fee_delta_threshold so unchanged peers are preserved in atomic fee_adjuster.txt writes.
- tests/test_p0_runtime_safety.py: add regression test verifying unchanged peers remain in the atomic fee_adjuster.txt snapshot (210/210 passing, 42.51% coverage).
@tunnelsentinel
tunnelsentinel Bot dismissed their stale review November 26, 2026 21:27

Superseded by a clean TunnelSentinel review of commit 8827d49, the current head of this pull request.

@TrezorHannes
TrezorHannes merged commit 3543e69 into main Nov 26, 2026
12 checks passed
@TrezorHannes
TrezorHannes deleted the fix/p0-runtime-safety-and-ci branch November 26, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant